# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  def is_on?(on, index)
    on.to_i == index.to_i ? "class='on'" : ""
  end
  
  def options_for_recommed_subject(selected = nil)
    options_for_select(RecommendSubject.flag_options.unshift(['不限', '']), selected.blank? ? nil : selected.to_i)
  end
  
  def options_for_item_status(selected = nil)
    options_for_select(Item.status_options.unshift(['不限', '']), selected.blank? ? nil : selected.to_i)
  end
  
  def options_for_item_style(selected = nil)
    options_for_select(ItemStyle.valid.map{|x| [x.name, x.id]}.unshift(['不限', '']), selected.blank? ? nil : selected.to_i)
  end
  
  def options_for_brand(selected = nil)
    options_for_select(Brand.valid.map{|x| [x.name, x.id]}.unshift(['不限', '']), selected.blank? ? nil : selected.to_i)
  end
  
  def options_for_cat1(selected = nil)
    options_for_select(ItemCategory.cat1.map{|x| [x.name, x.id]}.unshift(['一级分类', '']), selected.blank? ? nil : selected.to_i)
  end
  
  def show_category_for(item)
    [item.try(:cat1_name), item.try(:cat2_name)].reject{|x| x.blank? }.join(' > ')
  end
end
